#include <iostream>
#include <algorithm>

struct Interval {
    double left, right, cost;
    Interval (double left, double right, double cost)
              :left(left), right(right), cost(cost) {

    }
    Interval () {

    }
};

void readInput (std::vector<Interval> &input_data, int amount) {
    for (int iteration = 0; iteration < amount; ++iteration) {
        Interval current_interval;
        std::cin >> current_interval.left >> current_interval.right >>
                                             current_interval.cost;
        input_data.push_back(current_interval);
    }
}

bool intervalComparison (Interval first, Interval second) {
    if (first.right < second.right || (first.right == second.right &&
                                       first.left < second.left)) {
        return true;
    }
    return false;
}

bool prevAllowedComparsion(double value, Interval element) {
    if (element.right > value) {
        return true;
    }
    return false;
}

double countMaxCost (std::vector<Interval> &data) {
    int prev_allowed[data.size()];
    std::vector< std::pair<double, int> > max_if_picked(data.size());

    // counting previos interval that we can take
    prev_allowed[0] = -1;
    for (int current = 1; current < data.size(); ++current) {
        prev_allowed[current] = std::upper_bound(data.begin(),
                       data.begin() + current, data[current].left,
                       prevAllowedComparsion) - data.begin() - 1;
    }

    // counting max_cost if we take this interval
    max_if_picked[0].first = data[0].cost;
    max_if_picked[0].second = -1;
    for (int current = 1; current < data.size(); ++current) {
        int max_from_prev = current - 1;
        if (current == 1) {
            max_from_prev = 0;
            max_if_picked[1].second = 0;
            if (prev_allowed[1] == 0) {
                max_if_picked[1].first = data[0].cost + data[1].cost;
            } else {
                max_if_picked[1].first = data[1].cost;
            }
            continue;
        }
        if (max_if_picked[current - 1].first <
            max_if_picked[max_if_picked[current - 1].second].first) {
            max_from_prev = max_if_picked[current - 1].second;
        }
        while (max_from_prev != -1 && max_from_prev > prev_allowed[current]) {
            max_from_prev = max_if_picked[max_from_prev].second;
        }
        if (max_from_prev == -1) {
            max_if_picked[current].first = data[current].cost;
        } else {
            max_if_picked[current].first = data[current].cost +
                                           max_if_picked[max_from_prev].first;
        }
        if (max_if_picked[current - 1].first >
            max_if_picked[max_if_picked[current - 1].second].first) {
            max_if_picked[current].second = current - 1;
        } else {
            max_if_picked[current].second = max_if_picked[current - 1].second;
        }
    }

    // counting answer
    double answer = -1;
    for (int iteration = 0; iteration < data.size(); ++iteration) {
        answer = std::max(answer, max_if_picked[iteration].first);
    }

    /*for (int i = 0; i < data.size(); ++i) {
        std::cout << i << " " << prev_allowed[i] << " " << max_if_picked[i].first << "\n";
    } */
    return answer;
}

void printAnswer (double answer) {
    std::cout << answer;
}

int main () {
    int amount;
    std::cin >> amount;
    if (amount == 0) {
        std::cout << 0;
        return 0;
    }
    std::vector<Interval> data;
    readInput (data, amount);
    std::sort(data.begin(), data.end(), intervalComparison);
    double answer = countMaxCost (data);
    printAnswer (answer);
    return 0;
}
